<?php


/** 
 * 推荐管理
 * @author Legend. <xcx_legender@qq.com>
 * @param 
 * @return 
 */

namespace Admin\Controller;

class RecommendController extends BaseManageController 
{

	// 推送位 配置 #TODO 加入管理
	static $pos = array(
		'home',
	);
	protected $modelName = 'Common/Recommend';

	// 将视频推到推荐
	public function add($video_id = 0, $type = 'video')
	{
		
		$video_id = I('video_id', 0, 'intval');
		if (!$video_id)
		{
			return $this->error('项目信息错误!');
		}
		$serv = D('Common/Recommend', 'Service');
		$map['pos']      = 'home';
		$map['type']     = $type;
		$map['status']   = array('egt', 0);
		$map['video_id'] = intval($video_id);
		$data = $serv->where($map)->find();
		if ($data)
		{
			return $this->error('已推荐');
		}
		$data = $map;
		$data['sort']   = 0;
		$data['status'] = 0;
		$res = $serv->add($data);
		$res ? $this->success('添加成功') : $this->error($serv->getError());
	}

	// 排序
	public function index()
	{
		$map['pos'] = 'home';
		$lists = $this->getList(D('Common/Recommend', 'Service'), $map, 'sort desc');
		int_to_string($lists);
		$this->_list = $lists;
		$this->display();
	}
}